﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            //如果一个数组保存元素是有序的（从大到小），向这个数组中插入一个数，使得插入后的数组元素仍然保持有序。
            int[] a = new int[6];
            a[0] = 452;
            a[1] = 651;
            a[2] = 850;
            a[3] = 931;
            a[4] = 956;
            Console.WriteLine("原来排序:");
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] != 0)
                {
                    Console.Write(a[i] + " ");
                }
            }
            Console.WriteLine();
            Console.WriteLine("请插入一个数:");
            a[5] = int.Parse(Console.ReadLine());
            int temp = 0;
            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < a.Length - 1 - i; j++)
                {
                    if (a[j] < a[j + 1])
                    {
                        temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            Console.WriteLine("插入数后的排序为:");
            for (int i = 0; i < a.Length; i++)
            {
                Console.Write(a[i] + " ");
            }
        }
    }
}
